<template>
  <div class="profile-container">
    <!-- 用户信息头部 -->
    <div class="user-header">
      <div class="user-basic">
        <div class="user-avatar" @click="showAvatarDialog">
          <el-avatar
            :size="80"
            :style="{ backgroundColor: '#e02020' }"
            :src="currentAvatar"
          >
            {{ account.displayAvatar }}
          </el-avatar>
          <div class="avatar-edit-tip">
            <el-icon><Camera /></el-icon>
          </div>
        </div>
        <div class="user-info">
          <div class="username">
            {{ account.isLogin ? account.info?.username : "未登录" }}
          </div>
          <div class="user-id" v-if="account.isLogin">
            用户ID: {{ account.info?.id }}
          </div>
          <div class="user-actions" v-if="!account.isLogin">
            <el-button type="primary" size="small" @click="goToLogin"
              >立即登录</el-button
            >
            <el-button size="small" @click="goToSignup">注册账号</el-button>
          </div>
        </div>
      </div>
      <div class="user-stats" v-if="account.isLogin">
        <div class="stat-item" @click="goToOrders">
          <div class="stat-number">0</div>
          <div class="stat-label">待付款</div>
        </div>
        <div class="stat-item" @click="goToOrders">
          <div class="stat-number">0</div>
          <div class="stat-label">待发货</div>
        </div>
        <div class="stat-item" @click="goToOrders">
          <div class="stat-number">0</div>
          <div class="stat-label">待收货</div>
        </div>
        <div class="stat-item" @click="goToEvaluations">
          <div class="stat-number">0</div>
          <div class="stat-label">待评价</div>
        </div>
      </div>
    </div>

    <!-- 未登录提示 -->
    <div v-if="!account.isLogin" class="not-login-prompt">
      <div class="prompt-content">
        <el-icon><User /></el-icon>
        <div class="prompt-text">登录后查看个人中心</div>
      </div>
    </div>

    <!-- 已登录内容 -->
    <div v-else class="profile-content">
      <!-- 我的订单 -->
      <div class="section-card">
        <div class="section-header">
          <div class="section-title">
            <el-icon><Tickets /></el-icon>
            我的订单
          </div>
          <div class="section-more" @click="goToOrders">
            查看全部
            <el-icon><ArrowRight /></el-icon>
          </div>
        </div>
        <div class="order-status">
          <div class="status-item" @click="goToOrders">
            <div class="status-icon payment">
              <el-icon><Money /></el-icon>
            </div>
            <div class="status-text">待付款</div>
          </div>
          <div class="status-item" @click="goToOrders">
            <div class="status-icon delivery">
              <el-icon><Van /></el-icon>
            </div>
            <div class="status-text">待发货</div>
          </div>
          <div class="status-item" @click="goToOrders">
            <div class="status-icon receive">
              <el-icon><Box /></el-icon>
            </div>
            <div class="status-text">待收货</div>
          </div>
          <div class="status-item" @click="goToEvaluations">
            <div class="status-icon evaluation">
              <el-icon><ChatDotRound /></el-icon>
            </div>
            <div class="status-text">待评价</div>
          </div>
          <div class="status-item" @click="goToOrders">
            <div class="status-icon after-sale">
              <el-icon><Refresh /></el-icon>
            </div>
            <div class="status-text">退款/售后</div>
          </div>
        </div>
      </div>

      <!-- 常用功能 -->
      <div class="section-card">
        <div class="section-header">
          <div class="section-title">
            <el-icon><Menu /></el-icon>
            常用功能
          </div>
        </div>
        <div class="function-grid">
          <div class="function-item" @click="goToCart">
            <div class="function-icon cart">
              <el-icon><ShoppingCart /></el-icon>
            </div>
            <div class="function-text">购物车</div>
          </div>
          <div class="function-item" @click="goToEvaluations">
            <div class="function-icon star">
              <el-icon><Star /></el-icon>
            </div>
            <div class="function-text">我的评价</div>
          </div>
          <div class="function-item" @click="showAddressDialog">
            <div class="function-icon location">
              <el-icon><Location /></el-icon>
            </div>
            <div class="function-text">收货地址</div>
          </div>
          <div class="function-item" @click="showSecurityDialog">
            <div class="function-icon lock">
              <el-icon><Lock /></el-icon>
            </div>
            <div class="function-text">账户安全</div>
          </div>
          <div class="function-item" @click="showCustomerService">
            <div class="function-icon service">
              <el-icon><Phone /></el-icon>
            </div>
            <div class="function-text">客服中心</div>
          </div>
          <div class="function-item" @click="logout">
            <div class="function-icon logout">
              <el-icon><SwitchButton /></el-icon>
            </div>
            <div class="function-text">退出登录</div>
          </div>
        </div>
      </div>

      <!-- 会员中心 -->
      <div class="section-card">
        <div class="section-header">
          <div class="section-title">
            <el-icon><Trophy /></el-icon>
            会员中心
          </div>
        </div>
        <div class="vip-content">
          <div class="vip-info">
            <div class="vip-level">普通会员</div>
            <div class="vip-desc">享受会员专属权益</div>
          </div>
          <el-button type="warning" size="small" plain>开通会员</el-button>
        </div>
      </div>

      <!-- 我的服务 -->
      <div class="section-card">
        <div class="section-header">
          <div class="section-title">
            <el-icon><Tools /></el-icon>
            我的服务
          </div>
        </div>
        <div class="service-grid">
          <div class="service-item">
            <div class="service-icon">
              <el-icon><Aim /></el-icon>
            </div>
            <div class="service-text">以旧换新</div>
          </div>
          <div class="service-item">
            <div class="service-icon">
              <el-icon><OfficeBuilding /></el-icon>
            </div>
            <div class="service-text">企业购</div>
          </div>
          <div class="service-item">
            <div class="service-icon">
              <el-icon><Present /></el-icon>
            </div>
            <div class="service-text">花币</div>
          </div>
          <div class="service-item">
            <div class="service-icon">
              <el-icon><Ticket /></el-icon>
            </div>
            <div class="service-text">优惠券</div>
          </div>
          <div class="service-item">
            <div class="service-icon">
              <el-icon><Collection /></el-icon>
            </div>
            <div class="service-text">我的收藏</div>
          </div>
          <div class="service-item">
            <div class="service-icon">
              <el-icon><ChatLineRound /></el-icon>
            </div>
            <div class="service-text">我的消息</div>
          </div>
        </div>
      </div>
    </div>

    <!-- 修改头像对话框 -->
    <el-dialog
      v-model="avatarDialogVisible"
      title="修改头像"
      width="500px"
      align-center
    >
      <div class="avatar-dialog-content">
        <div class="avatar-preview">
          <el-avatar
            :size="120"
            :src="previewAvatar"
            :style="{ backgroundColor: '#e02020' }"
          >
            {{ account.displayAvatar }}
          </el-avatar>
        </div>

        <div class="avatar-upload">
          <el-upload
            class="avatar-uploader"
            action="#"
            :show-file-list="false"
            :before-upload="beforeAvatarUpload"
            :http-request="handleAvatarUpload"
            accept=".jpg,.jpeg,.png,.gif"
          >
            <el-button type="primary">
              <el-icon><Upload /></el-icon>
              选择图片
            </el-button>
          </el-upload>
          <div class="upload-tips">
            <div>建议尺寸：200×200像素</div>
            <div>支持 JPG、PNG 格式，文件小于 2MB</div>
          </div>
        </div>

        <div class="avatar-preset">
          <div class="preset-title">预设头像</div>
          <div class="preset-grid">
            <div
              v-for="avatar in presetAvatars"
              :key="avatar"
              class="preset-item"
              :class="{ active: previewAvatar === avatar }"
              @click="selectPresetAvatar(avatar)"
            >
              <el-avatar
                :size="50"
                :src="avatar"
                :style="{ backgroundColor: '#e02020' }"
              >
                {{ account.displayAvatar }}
              </el-avatar>
            </div>
          </div>
        </div>
      </div>

      <template #footer>
        <el-button @click="avatarDialogVisible = false">取消</el-button>
        <el-button type="primary" :loading="avatarLoading" @click="saveAvatar"
          >保存</el-button
        >
      </template>
    </el-dialog>

    <!-- 账户安全对话框 -->
    <el-dialog v-model="securityDialogVisible" title="账户安全" width="500px">
      <div class="security-content">
        <div class="security-item">
          <div class="security-info">
            <div class="security-title">登录密码</div>
            <div class="security-desc">定期修改密码有助于保护账户安全</div>
          </div>
          <el-button type="primary" text @click="showChangePasswordDialog"
            >修改</el-button
          >
        </div>
        <div class="security-item">
          <div class="security-info">
            <div class="security-title">账户绑定</div>
            <div class="security-desc">绑定手机、邮箱等</div>
          </div>
          <el-button type="primary" text>管理</el-button>
        </div>
      </div>
    </el-dialog>

    <!-- 修改密码对话框 -->
    <el-dialog
      v-model="passwordDialogVisible"
      title="修改密码"
      width="400px"
      align-center
    >
      <el-form
        :model="passwordForm"
        :rules="passwordRules"
        ref="passwordFormRef"
        label-width="80px"
      >
        <el-form-item label="原密码" prop="oldPassword">
          <el-input
            v-model="passwordForm.oldPassword"
            type="password"
            placeholder="请输入原密码"
            show-password
          ></el-input>
        </el-form-item>

        <el-form-item label="新密码" prop="newPassword">
          <el-input
            v-model="passwordForm.newPassword"
            type="password"
            placeholder="请输入新密码"
            show-password
          ></el-input>
        </el-form-item>

        <el-form-item label="确认密码" prop="confirmPassword">
          <el-input
            v-model="passwordForm.confirmPassword"
            type="password"
            placeholder="请再次输入新密码"
            show-password
          ></el-input>
        </el-form-item>
      </el-form>

      <template #footer>
        <el-button @click="passwordDialogVisible = false">取消</el-button>
        <el-button
          type="primary"
          :loading="passwordLoading"
          @click="changePassword"
        >
          确认修改
        </el-button>
      </template>
    </el-dialog>

    <!-- 收货地址对话框 -->
    <el-dialog v-model="addressDialogVisible" title="收货地址" width="500px">
      <div class="dialog-content">
        <el-empty description="暂无收货地址" />
        <div class="dialog-actions">
          <el-button type="primary">添加新地址</el-button>
        </div>
      </div>
    </el-dialog>

    <!-- 客服中心对话框 -->
    <el-dialog v-model="serviceDialogVisible" title="客服中心" width="400px">
      <div class="dialog-content">
        <div class="service-contact">
          <div class="contact-item">
            <el-icon><Phone /></el-icon>
            <div class="contact-info">
              <div class="contact-title">客服热线</div>
              <div class="contact-number">400-830-8300</div>
            </div>
          </div>
          <div class="contact-item">
            <el-icon><ChatDotRound /></el-icon>
            <div class="contact-info">
              <div class="contact-title">在线客服</div>
              <div class="contact-time">9:00-18:00</div>
            </div>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted, nextTick } from "vue";
import { useRouter } from "vue-router";
import { ElMessage, type FormInstance, type FormRules } from "element-plus";
import Account from "../base/AccountStore";
import { startRequest, RequestPath, worker } from "../base/RequestWork";

const router = useRouter();
const account = Account();

// 对话框状态
const avatarDialogVisible = ref(false);
const securityDialogVisible = ref(false);
const passwordDialogVisible = ref(false);
const addressDialogVisible = ref(false);
const serviceDialogVisible = ref(false);

// 头像相关
const currentAvatar = ref(account.info?.avatar || "");
const previewAvatar = ref("");
const avatarLoading = ref(false);
const selectedFile = ref<File | null>(null);
const presetAvatars = ref([
  "/src/assets/images/touxiang.webp",
]);

// 密码修改相关
const passwordFormRef = ref<FormInstance>();
const passwordLoading = ref(false);
const passwordForm = reactive({
  oldPassword: "",
  newPassword: "",
  confirmPassword: "",
});

const passwordRules: FormRules = {
  oldPassword: [{ required: true, message: "请输入原密码", trigger: "blur" }],
  newPassword: [
    { required: true, message: "请输入新密码", trigger: "blur" },
    {
      validator: (_, value, callback) => {
        if (value === passwordForm.oldPassword) {
          callback(new Error("新密码不能与原密码相同"));
        } else {
          callback();
        }
      },
      trigger: "blur",
    },
  ],
  confirmPassword: [
    { required: true, message: "请确认新密码", trigger: "blur" },
    {
      validator: (_, value, callback) => {
        if (value !== passwordForm.newPassword) {
          callback(new Error("两次输入的密码不一致"));
        } else {
          callback();
        }
      },
      trigger: "blur",
    },
  ],
};

// 组件挂载时初始化头像
onMounted(() => {
  if (account.info?.avatar) {
    currentAvatar.value = account.info.avatar;
  }
});

// 显示修改头像对话框
const showAvatarDialog = () => {
  if (!account.isLogin) {
    ElMessage.warning("请先登录");
    return;
  }
  previewAvatar.value = currentAvatar.value;
  selectedFile.value = null;
  avatarDialogVisible.value = true;
};

// 头像上传前验证
const beforeAvatarUpload = (file: File) => {
  const isJPGOrPNG =
    file.type === "image/jpeg" ||
    file.type === "image/png" ||
    file.type === "image/gif";
  const isLt2M = file.size / 1024 / 1024 < 2;

  if (!isJPGOrPNG) {
    ElMessage.error("头像只能是 JPG/PNG/GIF 格式!");
    return false;
  }
  if (!isLt2M) {
    ElMessage.error("头像大小不能超过 2MB!");
    return false;
  }

  // 保存文件引用
  selectedFile.value = file;

  // 预览图片
  const reader = new FileReader();
  reader.onload = (e) => {
    previewAvatar.value = e.target?.result as string;
  };
  reader.readAsDataURL(file);

  return false; // 阻止自动上传
};

// 处理头像上传
const handleAvatarUpload = () => {
  // 这里可以添加上传到服务器的逻辑
  // 目前只是本地预览
};

// 选择预设头像
const selectPresetAvatar = (avatar: string) => {
  previewAvatar.value = avatar;
  selectedFile.value = null; // 清除文件选择
};

// 保存头像到服务器
const saveAvatar = async () => {
  if (!previewAvatar.value) {
    ElMessage.warning("请选择头像");
    return;
  }

  avatarLoading.value = true;

  try {
    let finalAvatarUrl = previewAvatar.value;

    // 如果有新上传的文件，先上传到服务器
    if (selectedFile.value) {
      const formData = new FormData();
      formData.append("file", selectedFile.value);

      // 使用 worker 直接请求
      const uploadResponse = await worker.request({
        method: "post",
        url: RequestPath.imageUpload,
        data: formData,
        headers: {
          "Content-Type": "multipart/form-data",
          token: account.token || "",
        },
      });

      if (uploadResponse.data.msg === "ok" && uploadResponse.data.url) {
        finalAvatarUrl = uploadResponse.data.url;
      } else {
        throw new Error(uploadResponse.data.error || "图片上传失败");
      }
    }

    // 尝试更新用户头像信息到服务器
    try {
      const avatarResponse = await startRequest(
        RequestPath.changeAvatar,
        "post",
        {
          avatar: finalAvatarUrl,
        }
      );

      if (avatarResponse.data.msg !== "ok") {
        throw new Error(avatarResponse.data.error || "更新头像失败");
      }
    } catch (avatarError: any) {
      console.warn("更新头像接口不存在或失败，使用本地存储:", avatarError);
    }

    // 更新本地状态
    currentAvatar.value = finalAvatarUrl;

    // 更新账户信息
    if (account.info) {
      const updatedUserInfo = {
        ...account.info,
        avatar: finalAvatarUrl,
      };

      // 更新本地存储
      account.login({
        info: updatedUserInfo,
        token: account.token,
      });
    }

    ElMessage.success("头像修改成功");
    avatarDialogVisible.value = false;
  } catch (error: any) {
    console.error("头像修改失败:", error);

    if (error.code === "ERR_NETWORK") {
      ElMessage.error("网络连接失败，请检查后端服务是否运行");
    } else if (error.response?.status === 404) {
      ElMessage.error("上传接口不存在，请联系管理员");
    } else if (error.message) {
      ElMessage.error(error.message);
    } else {
      ElMessage.error("头像修改失败，请稍后重试");
    }
  } finally {
    avatarLoading.value = false;
  }
};

// 显示修改密码对话框
const showChangePasswordDialog = () => {
  passwordForm.oldPassword = "";
  passwordForm.newPassword = "";
  passwordForm.confirmPassword = "";
  nextTick(() => {
    passwordDialogVisible.value = true;
  });
};

const changePassword = async () => {
  if (!passwordFormRef.value) return;

  const valid = await passwordFormRef.value.validate();
  if (!valid) return;

  passwordLoading.value = true;
  try {
    const response = await startRequest(RequestPath.changePassword, "post", {
      oldPassword: passwordForm.oldPassword,
      newPassword: passwordForm.newPassword,
    });

    if (response.data.msg === "ok") {
      ElMessage.success("密码修改成功");
      passwordDialogVisible.value = false;
      passwordFormRef.value.resetFields();
    } else {
      ElMessage.error(response.data.error || "密码修改失败");
    }
  } catch (error: any) {
    ElMessage.error(error.response?.data?.error || "密码修改失败");
  } finally {
    passwordLoading.value = false;
  }
};

// 其他方法
const goToLogin = () => {
  router.push({ name: "login" });
};

const goToSignup = () => {
  router.push({ name: "login" });
};

const goToOrders = () => {
  if (!account.isLogin) {
    ElMessage.warning("请先登录");
    return;
  }
  router.push({ name: "order" });
};

const goToCart = () => {
  if (!account.isLogin) {
    ElMessage.warning("请先登录");
    return;
  }
  router.push({ name: "shopCar" });
};

const goToEvaluations = () => {
  if (!account.isLogin) {
    ElMessage.warning("请先登录");
    return;
  }
  router.push({ name: "evaluationList" });
};

const showSecurityDialog = () => {
  if (!account.isLogin) {
    ElMessage.warning("请先登录");
    return;
  }
  securityDialogVisible.value = true;
};

const showAddressDialog = () => {
  if (!account.isLogin) {
    ElMessage.warning("请先登录");
    return;
  }
  addressDialogVisible.value = true;
};

const showCustomerService = () => {
  serviceDialogVisible.value = true;
};

const logout = () => {
  account.logout();
  ElMessage.success("已退出登录");
};
</script>

<style scoped>
.profile-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  background: #f5f5f5;
  min-height: 100vh;
}

/* 用户头部 */
.user-header {
  background: white;
  border-radius: 8px;
  padding: 30px;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.user-basic {
  display: flex;
  align-items: center;
  gap: 20px;
}

.user-avatar {
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
}

.user-info .username {
  font-size: 24px;
  font-weight: 600;
  color: #333;
  margin-bottom: 8px;
}

.user-info .user-id {
  font-size: 14px;
  color: #666;
  margin-bottom: 12px;
}

.user-actions {
  display: flex;
  gap: 10px;
}

.user-stats {
  display: flex;
  gap: 40px;
}

.stat-item {
  text-align: center;
  cursor: pointer;
  padding: 10px;
  border-radius: 6px;
  transition: background-color 0.3s;
}

.stat-item:hover {
  background: #f8f9fa;
}

.stat-number {
  font-size: 24px;
  font-weight: 700;
  color: #e02020;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 14px;
  color: #666;
}

/* 未登录提示 */
.not-login-prompt {
  background: white;
  border-radius: 8px;
  padding: 60px 20px;
  text-align: center;
  margin-bottom: 20px;
}

.prompt-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

.prompt-content .el-icon {
  font-size: 60px;
  color: #ccc;
}

.prompt-text {
  font-size: 16px;
  color: #666;
}

/* 内容区域 */
.profile-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section-card {
  background: white;
  border-radius: 8px;
  padding: 20px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #f0f0f0;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
  color: #333;
}

.section-title .el-icon {
  color: #e02020;
}

.section-more {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  color: #666;
  cursor: pointer;
  transition: color 0.3s;
}

.section-more:hover {
  color: #e02020;
}

/* 订单状态 */
.order-status {
  display: flex;
  justify-content: space-around;
}

.status-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 10px;
  border-radius: 6px;
  transition: background-color 0.3s;
}

.status-item:hover {
  background: #f8f9fa;
}

.status-icon {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: white;
}

.status-icon.payment {
  background: #ff6b6b;
}
.status-icon.delivery {
  background: #4ecdc4;
}
.status-icon.receive {
  background: #45b7d1;
}
.status-icon.evaluation {
  background: #96ceb4;
}
.status-icon.after-sale {
  background: #feca57;
}

.status-text {
  font-size: 14px;
  color: #333;
}

/* 功能网格 */
.function-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 20px;
}

.function-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 15px 10px;
  border-radius: 6px;
  transition: background-color 0.3s;
}

.function-item:hover {
  background: #f8f9fa;
}

.function-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: white;
}

.function-icon.cart {
  background: #e02020;
}
.function-icon.star {
  background: #ff9500;
}
.function-icon.location {
  background: #34c759;
}
.function-icon.lock {
  background: #5856d6;
}
.function-icon.service {
  background: #af52de;
}
.function-icon.logout {
  background: #8e8e93;
}

.function-text {
  font-size: 14px;
  color: #333;
  text-align: center;
}

/* 会员中心 */
.vip-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  background: linear-gradient(135deg, #ffd700, #ff9500);
  border-radius: 8px;
  color: white;
}

.vip-level {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 4px;
}

.vip-desc {
  font-size: 14px;
  opacity: 0.9;
}

/* 服务网格 */
.service-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 20px;
}

.service-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 15px 10px;
  border-radius: 6px;
  transition: background-color 0.3s;
}

.service-item:hover {
  background: #f8f9fa;
}

.service-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #e02020;
  background: #fff2f2;
}

.service-text {
  font-size: 14px;
  color: #333;
  text-align: center;
}

/* 对话框内容 */
.dialog-content {
  padding: 10px 0;
}

.security-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 0;
  border-bottom: 1px solid #f0f0f0;
}

.security-item:last-child {
  border-bottom: none;
}

.security-info {
  flex: 1;
}

.security-title {
  font-size: 16px;
  color: #333;
  margin-bottom: 4px;
}

.security-desc {
  font-size: 12px;
  color: #666;
}

.service-contact {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 8px;
}

.contact-item .el-icon {
  font-size: 24px;
  color: #e02020;
}

.contact-title {
  font-size: 16px;
  color: #333;
  margin-bottom: 4px;
}

.contact-number,
.contact-time {
  font-size: 14px;
  color: #666;
}

.dialog-actions {
  text-align: center;
  padding: 20px 0;
}

/* 头像对话框内容 */
.avatar-dialog-content {
  text-align: center;
}

.avatar-preview {
  margin-bottom: 20px;
}

.avatar-upload {
  margin-bottom: 20px;
  padding: 20px;
  border: 1px dashed #dcdfe6;
  border-radius: 6px;
  background: #fafafa;
}

.upload-tips {
  margin-top: 10px;
  font-size: 12px;
  color: #999;
  line-height: 1.5;
}

.avatar-preset {
  border-top: 1px solid #f0f0f0;
  padding-top: 20px;
}

.preset-title {
  font-size: 14px;
  color: #333;
  margin-bottom: 10px;
  text-align: left;
  font-weight: 600;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.preset-item {
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  transition: all 0.3s;
  border: 2px solid transparent;
}

.preset-item:hover {
  background: #f5f5f5;
  border-color: #e0e0e0;
}

.preset-item.active {
  background: #e6f7ff;
  border: 2px solid #1890ff;
}

/* 头像编辑提示样式 */
.avatar-edit-tip {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 24px;
  height: 24px;
  background: #e02020;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 12px;
  border: 2px solid white;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .profile-container {
    padding: 10px;
  }

  .user-header {
    flex-direction: column;
    gap: 20px;
    text-align: center;
  }

  .user-basic {
    flex-direction: column;
    text-align: center;
  }

  .user-stats {
    gap: 20px;
  }

  .order-status {
    flex-wrap: wrap;
    gap: 10px;
  }

  .function-grid,
  .service-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
  }

  .vip-content {
    flex-direction: column;
    gap: 15px;
    text-align: center;
  }

  .preset-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .function-grid,
  .service-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .user-stats {
    gap: 10px;
  }

  .stat-item {
    min-width: 70px;
  }
}
</style>